package com.xt.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.constant.ResultDTO;
import com.xt.back.entity.Course;
import com.xt.back.service.ICourseService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 课程信息表 前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@CrossOrigin
@RestController
@RequestMapping("/back/course")
@AllArgsConstructor
public class CourseController {

    private final ICourseService courseService;


    @PostMapping("/add")
    public ResultDTO<Boolean> addCourse(@RequestBody Course course){
        return ResultDTO.success(courseService.save(course));
    }

    @GetMapping("/remove")
    public ResultDTO<Boolean> deleteCourse(int id){
        return ResultDTO.success(courseService.removeById(id));
    }

    @PostMapping("/update")
    public ResultDTO<Boolean> updateCourse(@RequestBody Course course){
        return ResultDTO.success(courseService.updateById(course));
    }

    @PostMapping("/getCourseByPage")
    public ResultDTO<Page<Course>> getCourseByPage(@RequestBody Course course){
        return ResultDTO.success(courseService.getCourseByPage(course));
    }

    @GetMapping("/getAllCourse")
    public ResultDTO<List<Course>> getAllCourse(){
        return ResultDTO.success(courseService.list());
    }
}
